SQL SERVER 临时表的排序问题

2023/03/31

这篇文章发布于 408 天前,部分信息可能已经发生变化。

  • 起因:用户报一个功能bug,没有按照用户交期取数,可是测试环境无法重现。

    追踪才发现测试环境MSSQL 2016和正式环境MSSQL 2016执行结果不一致,测试环境:临时表按照预期排序,正式环境没有按照预期排序;

SELECT * INTO #tables FROM sys.tables ORDER BY name;
 
SELECT * FROM #tables; --测试环境MSSQL 2016按照name排序;正式环境没按照name排序
  • 正式环境MSSQL版本:

    Microsoft SQL Server 2016 (SP3) (KB5003279) - 13.0.6300.2 (X64) Aug 7 2021 01:20:37 Copyright (c) Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

  • 测试环境MSSQL版本(测试环境MSSQL版本比正式环境新一点)

Microsoft SQL Server 2016 (SP3-OD) (KB5006943) - 13.0.6404.1 (X64) Oct 18 2021 09:37:01 Copyright (c) Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

相关资料:

https://www.cnblogs.com/kerrycode/p/5172333.html